<?php
    require_once'../../config/config.php';
    class dbconnect
    {
        public $host = 'localhost';
        public $user = 'root';
        public $pass = 'root';
        public $database ='battrang';
        public $connect;
        public function dbconnect()
        {
            // GET CONNECT TO DATABASE
            $this->connect = mysqli_connect($this->host,$this->user,$this->pass,$this->database) 
                                or die('could not connect to sever'.mysqli_error($this->connect));
            
            // CHECK CONNECT SUCCSESS
            //if($this->connect != ''){echo "Connect to database success!";}
        }
        public function func_query($str_query)
        {
           $query = mysqli_query($this->connect,$str_query) 
                                or die(mysqli_error($this->connect));
            return $query;
        }
        public function fetch($res_query)
        {
            $result = mysqli_fetch_array($res_query,MYSQLI_ASSOC);
            return $result;
        }
        public function check_login($user,$pass)
        {
            $sql = "SELECT * FROM ";
            $sql.="bt_user Where fld_id='".$user."'";
            $sql.= " and fld_pass='".$pass."'";
            $result = $this->func_query($sql);
            $count = mysqli_num_rows($result);
            if($count>0){
                return 1;
            }else{
                return 0;
            }
        }
    }
?>